package com.zyd.blog.personal.controller;

import com.zyd.blog.business.annotation.BussinessLog;
import com.zyd.blog.business.enums.PlatformEnum;
import com.zyd.blog.framework.object.PageResult;
import com.zyd.blog.framework.object.ResponseVO;
import com.zyd.blog.homeart.service.BackstageFineArtService;
import com.zyd.blog.homeart.service.BackstageRotationChartService;
import com.zyd.blog.homeart.service.ICommentService;
import com.zyd.blog.homeart.util.ResponseObject;
import com.zyd.blog.homeart.util.UuidUtil;
import com.zyd.blog.persistence.beans.DesignArticle;
import com.zyd.blog.persistence.beans.FineArt;
import com.zyd.blog.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liusongqi
 * @since 2020-03-24
 */
@Controller
@RequestMapping("/backstageFineArt")
public class BackstageFineArtController {
    private final Logger logger = LoggerFactory.getLogger(BackstageRotationChartController.class);
    @Autowired
    private BackstageFineArtService backstageFineArtService;
    @Autowired
    private UuidUtil uuidUtil;
    @Autowired
    private ICommentService iCommentService;
    /**     艺术精品   后台人员内部发送的文章
     *    渲染
     */
    @RequestMapping(value = "/softAll", method = RequestMethod.POST)
    @ResponseBody
    public PageResult soft(int page, int count) {
        logger.info("/backstageFineArt/softAll 艺术精品 全部,page={},count={}",page,count);
        return backstageFineArtService.softBackstage(page,count);
    }
    @BussinessLog("艺术精品")
    @GetMapping(value = "/get")
    public ModelAndView backstageSoft(Model model, String id,String state,String userId) {
        logger.info("/backstageFineArt/get 跳转详情,id={},state={},userId={}",id,state,userId);
        model.addAttribute("item",id);
        model.addAttribute("state",state);
        model.addAttribute("userId",userId);
        if (state.equals("0")){
            return ResultUtil.view("fineArt/qualityDetails");
        }
        return ResultUtil.view("fineArt/informationDetails");

    }
    @BussinessLog("艺术精品")
    @GetMapping(value = "/pass")
    public ModelAndView pass(Model model, String id,String state) {
        logger.info("/backstageFineArt/get 审核,id={}",id);
        model.addAttribute("item",id);
        model.addAttribute("state",state);
        return ResultUtil.view("fineArt/beforeAudit");
    }
    @BussinessLog("新增艺术精品")
    @GetMapping(value = "/addFine")
    public ModelAndView adSoft(Model model) {
        logger.info("/backstageFineArt/addFine 新增界面");
        return ResultUtil.view("fineArt/issueAdvisory");
    }
    /**
     *     根据文章 id  获取具体内容
     */
    @RequestMapping(value = "/specific", method = RequestMethod.POST)
    @ResponseBody
    public ResponseObject specific(String fineId,String state)  {
        logger.info("/backstageFineArt/specific 获取具体内容, fineId={},state={}", fineId,state);
        ResponseObject ob = new ResponseObject();
        Map<String,Object> specific;
        try {
            specific = backstageFineArtService.specific(fineId,state);
        } catch (Exception e) {
            ob.setCode(1);
            ob.setMsg(e.getMessage());
            return ob;
        }
        ob.setCode(0);
        ob.setData(specific);
        ob.setMsg("success");
        return ob;
    }
    @RequestMapping(value = "/getInfo", method = RequestMethod.POST)
    @ResponseBody
    public ResponseVO get(String id) {
        logger.info("/backstageFineArt/getInfo 弹窗,id={}",id);
        return ResultUtil.success(null, backstageFineArtService.get(id));
    }

    @RequestMapping(value = "/updateIn", method = RequestMethod.POST)
    @ResponseBody
    public ResponseVO updateIn(FineArt fineArt) {
        logger.info("/backstageFineArt/updateIn 修改启用，fineArt={}",fineArt);
        return  ResultUtil.success(null, backstageFineArtService.updateIn(fineArt));
    }
    /**
     *     ui图 115  全部评论 以及评论回复的 3条
     */
    @RequestMapping(value = "/allComment", method = RequestMethod.POST)
    @BussinessLog(value = "/backstageFineArt/allComment 全部评论 ", platform = PlatformEnum.WEB, save = false)
    @ResponseBody
    public ResponseObject allComment(String answerId) {
        ResponseObject ob = new ResponseObject();
        Map<String, List> comment;
        try {
            comment = iCommentService.HTComment(answerId,"3");
        } catch (Exception e) {
            ob.setCode(1);
            ob.setMsg(e.getMessage());
            return ob;
        }
        ob.setCode(0);
        ob.setData(comment);
        ob.setMsg("success");
        return ob;
    }
    //添加文章 艺术精品
    @RequestMapping(value = "/insertSoft", method = RequestMethod.POST)
    @ResponseBody
    public ResponseObject insertFineArt(FineArt designArticle) {
        logger.info("/backstageFineArt/insertSoft 发布艺术精品，softProduct={}",designArticle);
        ResponseObject ob = new ResponseObject();
        Integer integer;
//        try {
        integer = backstageFineArtService.insertFineArt(designArticle);
//        } catch (Exception e) {
//            ob.setCode(1);
//            ob.setMsg(e.getMessage());
//            return ob;
//        }
        uuidUtil.importSongData();
        ob.setCode(0);
        ob.setData(integer);
        ob.setMsg("success");
        return ob;
    }


    //修改 艺术精品
    @RequestMapping(value = "/editSoft", method = RequestMethod.POST)
    public ResponseObject editSoft(String  fineId,String  fineTitle,String fineImage,String top,
                                   String  fineContent) {
        logger.info("/backstageFineArt/editSoft 修改艺术精品，fineId={},fineTitle={},fineImage={},top={},fineContent={}",fineId,fineTitle,fineImage,top,fineContent);
        ResponseObject ob = new ResponseObject();
        Integer integer;
        try {
            integer = backstageFineArtService.editFineArt(fineId,fineTitle,fineImage,top,fineContent);
        } catch (Exception e) {
            ob.setCode(1);
            ob.setMsg(e.getMessage());
            return ob;
        }
        uuidUtil.importSongData();
        ob.setCode(0);
        ob.setData(integer);
        ob.setMsg("success");
        return ob;
    }

    //删除 软装设计
    @RequestMapping(value = "/deleteSoft", method = RequestMethod.POST)
    @ResponseBody
    public ResponseVO deleteSoft(String[] ids) throws Exception {
        logger.info("/backstageFineArt/deleteSoft 删除软装设计，ids={}",ids);
        for (String id : ids) {
            backstageFineArtService.deleteFineArt(id);
        }
        uuidUtil.importSongData();
        return ResultUtil.success("成功删除 [" + ids.length + "] 个文章类型");
    }



    //搜索
    @RequestMapping(value = "/searchSoft", method = RequestMethod.POST)
    public ResponseObject searchDesign(String value, int page, int count) {
        logger.info("/backstageFineArt/searchSoft 搜索,value={},page={},count={}",value,page,count);
        ResponseObject ob = new ResponseObject();
        Map<String,Object> integer;
        try {
            integer = backstageFineArtService.searchDesign(value,page,count);
        } catch (Exception e) {
            ob.setCode(1);
            ob.setMsg(e.getMessage());
            return ob;
        }
        ob.setCode(0);
        ob.setData(integer);
        ob.setMsg("success");
        return ob;
    }

    /**
     * @param
     * @return    隐藏
     */
    @RequestMapping(value = "/hide", method = RequestMethod.POST)
    @ResponseBody
    public ResponseObject hide(String id,String commentId,String content) {
        logger.info("/rotationChart/stopUser 禁用用户 id={},commentId={},content={}",id,commentId,content);
        ResponseObject ob = new ResponseObject();
        Integer listall;
        listall = backstageFineArtService.hide(id,commentId,content);
        ob.setData(listall);
        ob.setCode(0);
        ob.setMsg("请求成功");
        return ob;
    }
    /**
     * @param
     * @return    删除评论
     */
    @RequestMapping(value = "/deleteComment", method = RequestMethod.POST)
    @ResponseBody
    public ResponseObject deleteComment(String id,String commentId,String userId) throws Exception {
        logger.info("/rotationChart/stopUser 禁用用户 id={},commentId={},userId={}",id,commentId,userId);
        ResponseObject ob = new ResponseObject();
        Integer listall;
        listall  = iCommentService.deleteComment(id,commentId,userId,"3");
        ob.setData(listall);
        ob.setCode(0);
        ob.setMsg("请求成功");
        return ob;

    }
}
